package br.com.minhasfinancas.api.model;

import java.util.Date;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;

import br.com.minhasfinancas.api.enums.Situacao;
import br.com.minhasfinancas.fw.model.AbstractModel;

@Entity
@NamedQueries({
	@NamedQuery(name = "Data.findAll", query = "SELECT d FROM Data d"),
	@NamedQuery(name = "Data.findById", query = "SELECT d FROM Data d WHERE d.id = :id"),
	@NamedQuery(name = "Data.findByData", query = "SELECT d FROM Data d WHERE d.data = :data"),
	@NamedQuery(name = "Data.findBySituacao", query = "SELECT d FROM Data d WHERE d.situacao = :situacao"),
	@NamedQuery(name = "Data.findByIdEager", query = "SELECT d FROM Data d LEFT JOIN FETCH d.receitas LEFT JOIN FETCH d.despesas WHERE d.id = :id")})
public class Data extends AbstractModel<Long> {
	private static final long serialVersionUID = 1L;
	
	public static final String FINDALL = "Data.findAll";
	public static final String FINDBYID = "Data.findByid";
	public static final String FINDBYDATA = "Data.findByData";
	public static final String FINDBYSITUACAO = "Data.findBySituacao";
	public static final String FINDBYIDEAGER = "Data.findByIdEager";

	@Id @GeneratedValue(strategy=GenerationType.SEQUENCE)
	@Column(name = "ID_DATA")
	private Long id;
	
	@NotNull
	@Column(name = "DATA")
	@Temporal(TemporalType.DATE)
	private Date data;
	
	@NotNull
	@Column(name = "SITUACAO", length = 10)
	@Enumerated(EnumType.STRING)
	private Situacao situacao;
	
	@ManyToMany(mappedBy="datas", fetch = FetchType.LAZY)
	private Set<Receita> receitas;
	
	@ManyToMany(mappedBy="datas", fetch = FetchType.LAZY)
	private Set<Despesa> despesas;
	
	@Override
	public Long getId() {
		return this.id;
	}
	
	@Override
	public void setId(Long id) {
		this.id = id;
	}

	public Situacao getSituacao() {
		return situacao;
	}

	public void setSituacao(Situacao situacao) {
		this.situacao = situacao;
	}

	public Date getData() {
		return data;
	}

	public void setData(Date data) {
		this.data = data;
	}

	public Set<Receita> getReceitas() {
		return receitas;
	}

	public void setReceitas(Set<Receita> receitas) {
		this.receitas = receitas;
	}

	public Set<Despesa> getDespesas() {
		return despesas;
	}

	public void setDespesas(Set<Despesa> despesas) {
		this.despesas = despesas;
	}
	
	
}
